<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CC的办公系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
</style>
<script type="text/javascript">
	$(function() {
		$("#form1").validationEngine();
		$(".datepicker").datepicker();
		filechange();
		function filechange(){
			if($("#da_type").val()==1){
				$(".wsfile").show();
				$(".ywfile").hide();
			}
			if($("#da_type").val()==2){
				$(".wsfile").hide();
				$(".ywfile").show();
			}
		}
		
		$("#da_type").change(function(){
			filechange();
		});
	
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),1,2) then call JumpErrorPage(2)

id=request("id")
submit=request("submit")
if id="" then
	'初始化空白单
	action="add"
	'初始化日期
	da_date=date()
else
 action="edit"
end if
if submit<>"" then
	'事务开始
	conn.BeginTrans
	on error resume next
	action=SafeRequest("action",0)
	da_owner=SafeRequest("da_owner",0)
	da_filename=SafeRequest("da_filename",0)
	da_recordnumber=SafeRequest("da_recordnumber",0)
	da_memo=SafeRequest("da_memo",0)
	da_type=SafeRequest("da_type",1)
	if da_type=1 then
		da_date=SafeRequest("da_date",0)
		da_filenumber=SafeRequest("da_filenumber",0)
	end if
	if da_type=2 then
		da_sheet=SafeRequest("da_sheet",1)
		da_year=SafeRequest("da_year",1)
	end if
	if action="edit" then
		operate="编辑"
		'如果是编辑状态，提交或保存按钮把所有信息更新
		if submit="保存" then
			if da_type=1 then sql_act="update dangan set da_date='"&da_date&"',da_owner='"&da_owner&"',da_filenumber='"&da_filenumber&"',da_filename='"&da_filename&"',da_recordnumber='"&da_recordnumber&"',da_memo='"&da_memo&"',da_type=1 where id="&id
			if da_type=2 then sql_act="update dangan set da_year="&da_year&",da_owner='"&da_owner&"',da_sheet="&da_sheet&",da_filename='"&da_filename&"',da_recordnumber='"&da_recordnumber&"',da_memo='"&da_memo&"',da_type=2 where id="&id
		end if

		if submit="删除" then
			sql_act="delete from dangan where id="&id
			operate="删除"
		end if
		call ExecuteCommand(sql_act,false)
	end if
	
	if action="add" then
		operate="新增"
		'如果是添加状态，新增和提交按钮起同样作用
		if da_type=1 then sql_act="insert into dangan(da_date,da_owner,da_filenumber,da_filename,da_recordnumber,da_memo,addid,da_type) values('"&da_date&"','"&da_owner&"','"&da_filenumber&"','"&da_filename&"','"&da_recordnumber&"','"&da_memo&"',2,1)"
		if da_type=2 then sql_act="insert into dangan(da_year,da_owner,da_sheet,da_filename,da_recordnumber,da_memo,addid,da_type) values("&da_year&",'"&da_owner&"',"&da_sheet&",'"&da_filename&"','"&da_recordnumber&"','"&da_memo&"',2,2)"
		id=ExecuteCommand(sql_act,true)
	end if
	
	
	
	'事务提交
	' if conn.Errors.Count=0 then 
		' conn.CommitTrans  '如果没有conn错误，则执行事务提交
	' else
		' conn.RollbackTrans '否则回滚
	' end if

	if err.number=0 then 
		conn.CommitTrans  '如果没有conn错误，则执行事务提交
	else
		conn.RollbackTrans '否则回滚
		'回滚后的其他操作
		'strerr=err.Description
		url=request.ServerVariables("http_host")&request.ServerVariables("url")
		Response.Write "数据库错误！<br /><font color=red>Error # " & CStr(Err.Number) & "<br />" & Err.Description & "<br />Source: " & Err.Source &"<br />错误页面："&url&"</font><br />"
		Response.End
	end if
	
end if

if operate="删除" then response.redirect("processfile.asp")
if id<>"" then
	sql = "select * from dangan where id="&id
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sql,conn,1,1
	if not rs.eof then
		da_date=rs("da_date")
		da_owner=rs("da_owner")
		da_filenumber=rs("da_filenumber")
		da_filename=rs("da_filename")
		da_recordnumber=rs("da_recordnumber")
		da_memo=rs("da_memo")
		da_type=rs("da_type")
		da_sheet=rs("da_sheet")
		da_year=rs("da_year")
	else
		'response.write("未找到数据")
		response.redirect("error.asp?id=1")
	end if
	rs.close
	set rs=nothing
end if
%>
<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="form1" name="form1" method="post" class="yform" role="application">
				<div class="type-select">
					<label for="da_type">档案类型*</label>
					<select name="da_type" id="da_type">
						<option value="1" <%if da_type=1 then response.write("selected='selected'")%>>文书档案</option>
						<option value="2" <%if da_type=2 then response.write("selected='selected'")%>>业务档案</option>
					</select>
				</div>
				<div class="type-text wsfile">
					<label for="da_date">日期*</label>
					<input class="datepicker" name="da_date" id="da_date" type="text" readonly="readonly" value="<%=da_date%>" />
				</div>
				<div class="type-text ywfile">
					<label for="da_year">年份*</label>
					<input class="validate[required,custom[onlyNumber],minSize[4],maxSize[4],min[2000],max[2020]]" name="da_year" id="da_year" type="text" maxlength="4" value="<%=da_year%>" />
				</div>
				<div class="type-text">
					<label for="da_recordnumber">档号/案卷号*</label>
					<input class="validate[required]" name="da_recordnumber" id="da_recordnumber" type="text" value="<%=da_recordnumber%>" />
				</div>
				<div class="type-text">
					<label for="da_owner">责任者/责任人*</label>
					<input class="validate[required]" name="da_owner" id="da_owner" type="text" value="<%=da_owner%>" />
				</div>
				<div class="type-text">
					<label for="da_filename">文件名/编号*</label>
					<input class="validate[required]" name="da_filename" id="da_filename" type="text" value="<%=da_filename%>" />
				</div>
				<div class="type-text wsfile">
					<label for="da_filenumber">文号*</label>
					<input name="da_filenumber" id="da_filenumber" type="text" value="<%=da_filenumber%>" />
				</div>
				<div class="type-text ywfile">
					<label for="da_sheet">张数*</label>
					<input class="validate[required,custom[onlyNumber],min[1]]" name="da_sheet" id="da_sheet" type="text" value="<%=da_sheet%>" />
				</div>
				<div class="type-text">
					<label for="da_memo">备注</label>
					<textarea name="da_memo" id="da_memo"><%=da_memo%></textarea>
				</div>
				<div class="type-button">
					<input id="id" type="hidden" value="<%=id%>" />
					<input id="action" name="action" type="hidden" value="<%=action%>" />
				<%if action="add" and CheckPostFlag(session("aaPostFlag"),1,3) then%>
					<input type="submit" id="submit_add" name="submit" value="新增" />
				<%end if%>
				<%if action="edit" and CheckPostFlag(session("aaPostFlag"),1,4) then%>
					<input type="submit" name="submit" value="保存" />
				<%end if%>
				<%if action="edit" and CheckPostFlag(session("aaPostFlag"),1,5) then%>
					<input type="submit" id="submit_del" name="submit" value="删除" />
				<%end if%>
				</div>
			</form>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

